﻿using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TunnelManager.Tools;

namespace TunnelManager.SearchAndReport.CO
{
    public partial class CO_YearReport : Form
    {
        public CO_YearReport()
        {
            InitializeComponent();
        }

        private void CO_YearReport_Load(object sender, EventArgs e)
        {

            this.reportViewer1.RefreshReport();
        }
        private void LocationPut()
        {
            reportViewer1.Size = new Size(this.ClientSize.Width, this.ClientSize.Height - 93);
            panel1.Location = new Point(0, this.ClientSize.Height - 80);
        }
        private void CO_YearReport_Resize(object sender, EventArgs e)
        {
            LocationPut();
        }

        private void reportViewer1_Load(object sender, EventArgs e)
        {
            //定义选择设备下拉框内容//
            string sql = "select DeviceID,Name from V_DeviceTable where TypeID='COVI'";
            SqlDBHelper sdh = new SqlDBHelper();
            DataTable dt = sdh.GetTable(sql);
            devicechose.DataSource = dt;

            LocationPut();

            TranTheParam();
            cO_YearReportTableAdapter.Fill(tunnelXAT1DataSet.CO_YearReport, dateTimePicker_COYear.Value.Year, devicechose.SelectedValue.ToString());
            this.reportViewer1.RefreshReport();
        }
        private void TranTheParam()
        {
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter("year", dateTimePicker_COYear.Value.Year.ToString()));
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter("user", User.Username));
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter("deviceid", devicechose.Text));
        }

        private void button_watch_Click(object sender, EventArgs e)
        {
            TranTheParam();
            cO_YearReportTableAdapter.Fill(tunnelXAT1DataSet.CO_YearReport, dateTimePicker_COYear.Value.Year, devicechose.SelectedValue.ToString());
            this.reportViewer1.RefreshReport();
        }

        private void button_watch_MouseEnter(object sender, EventArgs e)
        {
            this.Cursor = Cursors.Hand;
        }

        private void button_watch_MouseLeave(object sender, EventArgs e)
        {
            this.Cursor = Cursors.Arrow;
        }

        private void dateTimePicker_COMonth_ValueChanged(object sender, EventArgs e)
        {
            dateTimePicker_COYear.CustomFormat = "yyyy年";
        }
    }
}
